import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  UseInterceptors,
  ClassSerializerInterceptor,
  UseGuards,
} from '@nestjs/common';
import { ClassRoomsService } from './class-rooms.service';
import { CreateClassRoomDto } from './dto/create-class-room.dto';
import { UpdateClassRoomDto } from './dto/update-class-room.dto';
import {
  ApiBody,
  ApiOperation,
  ApiQuery,
  ApiResponse,
  ApiTags,
} from '@nestjs/swagger';
import { ClassRoom } from './entities/class-room.entity';
import { JwtGuard } from '../guards/jwt.guards';

@Controller('class-rooms')
@UseInterceptors(ClassSerializerInterceptor)
@UseGuards(JwtGuard) // 校验token是否通过
@ApiTags('教室模块')
export class ClassRoomsController {
  constructor(private readonly classRoomsService: ClassRoomsService) {}

  @Post()
  @ApiOperation({ summary: '创建教室' })
  @ApiBody({ type: CreateClassRoomDto, description: '' })
  @ApiResponse({
    status: 200,
    description: '成功返回200，失败返回400',
    type: CreateClassRoomDto,
  })
  create(@Body() createClassRoomDto: CreateClassRoomDto) {
    return this.classRoomsService.create(createClassRoomDto);
  }

  @Get()
  @ApiOperation({ summary: '教室列表' })
  findAll() {
    return this.classRoomsService.findAll();
  }

  @Get(':id')
  @ApiOperation({ summary: '教室详情' })
  @ApiQuery({ name: 'id', required: true, description: '课程id' })
  @ApiResponse({
    status: 200,
    description: '成功返回200，失败返回400',
    type: ClassRoom,
  })
  findOne(@Param('id') id: string) {
    return this.classRoomsService.findOne(+id);
  }

  @Patch(':id')
  @ApiOperation({ summary: '教室更新' })
  @ApiQuery({ name: 'id', required: true, description: '教室id' })
  @ApiBody({ type: UpdateClassRoomDto, description: '' })
  @ApiResponse({
    status: 200,
    description: '成功返回200，失败返回400',
    type: ClassRoom,
  })
  update(
    @Param('id') id: number,
    @Body() updateClassRoomDto: UpdateClassRoomDto,
  ) {
    return this.classRoomsService.update(id, updateClassRoomDto);
  }

  @Delete(':id')
  @ApiOperation({ summary: '教室删除' })
  @ApiQuery({
    name: 'id',
    required: true,
    description: '',
  })
  @ApiResponse({
    status: 200,
    description: '成功返回200，失败返回400',
    type: ClassRoom,
  })
  remove(@Param('id') id: number) {
    return this.classRoomsService.remove(+id);
  }
}
